package com.hly.musicbackground.model.boots.rest;

import com.hly.musicbackground.domain.FictionChapter;
import com.hly.musicbackground.model.boots.VO.FictionContentVO;
import com.hly.musicbackground.model.boots.service.FictionChapterService;
import com.hly.musicbackground.model.boots.service.FictionContentService;
import com.hly.musicbackground.model.user.service.UserLogService;
import com.hly.musicbackground.result.Code;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 小说内容
 * */
@RestController
@RequestMapping("/api/fictionContent")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "小说内容")
public class FictionContentController {

    private final FictionContentService fictionContentService;
    private final FictionChapterService fictionChapterService;
    private final UserLogService userLogService;


    /**
     * 获取小说章节内容
     * @param id 章节id
     * */
    @GetMapping("/content/{id}")
    @ApiOperation(value = "获取小说章节内容")
    public Result<FictionContentVO> detail(@PathVariable("id") int id){
        FictionChapter byId = fictionChapterService.getById(id);
        if (byId == null){
            Code.BUSINESS_ERR("该章节不存在");
        }
        FictionContentVO fictionContent = fictionContentService.getFictionContent(byId);
        fictionContent.setFictionContent(null);
        return Result.ok(fictionContent);
    }



}